package com.destinomusical.epura.base;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.destinomusical.epura.obj.Usuario;
import com.smartthinking.destinomusical.R;

public class ListBaseActivity extends ListActivity {
	public Usuario usuario;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		usuario=(Usuario)getIntent().getParcelableExtra("usuario");
	}
	
	public void onClickButtonAtras(View view) {
		finish();

	}

	public void setTopBar(int backGround, int btnTitle, int Title) {
		if (backGround == 0 && btnTitle == 0) {
			((Button) findViewById(R.id.custom)).setVisibility(View.INVISIBLE);
		}else{
			Button customButton = (Button) findViewById(R.id.custom);
			customButton.setBackgroundResource(backGround);
			customButton.setText(getString(btnTitle));
			customButton.setVisibility(View.VISIBLE);
		}
		((TextView) findViewById(R.id.title)).setText(Title);

	}
	
	public void setTopBar(int backGround, int btnTitle, String Title) {
		if (backGround == 0 && btnTitle == 0) {
			((Button) findViewById(R.id.custom)).setVisibility(View.INVISIBLE);
		}else{
			Button customButton = (Button) findViewById(R.id.custom);
			customButton.setBackgroundResource(backGround);
			customButton.setText(getString(btnTitle));
			customButton.setVisibility(View.VISIBLE);
		}
		((TextView) findViewById(R.id.title)).setText(Title);

	}
	
	public void setTopBar(int backGround, int btnTitle, int Title,int bullet) {
		if (backGround == 0 && btnTitle == 0) {
			((Button) findViewById(R.id.custom)).setVisibility(View.INVISIBLE);
		}else{
			Button customButton = (Button) findViewById(R.id.custom);
			customButton.setBackgroundResource(backGround);
			customButton.setText(getString(btnTitle));
			customButton.setVisibility(View.VISIBLE);
			customButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, bullet,0);
		}
		((TextView) findViewById(R.id.title)).setText(Title);

	}
	public void setTopBar(int backGround, int btnTitle, String  title,int bullet) {
		if (backGround == 0 && btnTitle == 0) {
			((Button) findViewById(R.id.custom)).setVisibility(View.INVISIBLE);
		}else{
			Button customButton = (Button) findViewById(R.id.custom);
			customButton.setBackgroundResource(backGround);
			customButton.setText(getString(btnTitle));
			customButton.setVisibility(View.VISIBLE);
			customButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, bullet,0);
		}
		((TextView) findViewById(R.id.title)).setText(title);
		
	}

	@Override
	protected void onStart(){
		super.onStart();
		//usuario=(Usuario)getIntent().getParcelableExtra("usuario");
		
	}
	
	public boolean isEmail(String correo) {
		if (correo != null && !correo.equals("")) {
			Pattern pat = null;
			Matcher mat = null;
			pat = Pattern
					.compile("^([0-9a-zA-Z]([_.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+([a-zA-Z]{2,9}.)+[a-zA-Z]{2,3})$");
			mat = pat.matcher(correo);
			if (mat.find()) {
				// System.out.println("[" + mat.group() + "]");
				return true;
			} else {
				Toast.makeText(this, getString(R.string.msg_enter_mail),
						Toast.LENGTH_SHORT).show();
				return false;
			}
		} else {
			Toast.makeText(this, getString(R.string.msg_enter_mail),
					Toast.LENGTH_SHORT).show();
			return false;
		}
	}

	public boolean isValid(String cadena, int stringId) {
		String temp = cadena.trim();
		if (temp == null || temp.equals("")) {
			Toast.makeText(this, getString(stringId), Toast.LENGTH_SHORT)
					.show();
			return false;
		} else

			return true;
	}
}
